package com.clkj.sunhelp.adapter.list;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.bean.PublicityOfApplyResultListItem;

import java.util.List;

/**
 * Created by Administrator on 2017/3/28.
 */

public class ListAdapterForPublicityOfApplyResult extends BaseAdapter {


    List<PublicityOfApplyResultListItem> mPublicityList;
    Context mContext;
    LayoutInflater mLayoutInflater;

    public ListAdapterForPublicityOfApplyResult(Context context, List<PublicityOfApplyResultListItem> publicityList) {
        mContext = context;
        this.mPublicityList = publicityList;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mPublicityList.size();
    }

    @Override
    public Object getItem(int i) {
        return mPublicityList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.list_item_publicity_of_apply_result, null);
            viewHolder = new ViewHolder();
            viewHolder.tvIndexNo = (TextView) view.findViewById(R.id.tv_index_no);
            viewHolder.tvHomeOwnerName = (TextView) view.findViewById(R.id.tv_home_owner_name);

            viewHolder.tvFamilyPersonNum = (TextView) view.findViewById(R.id.tv_family_person_num);
            viewHolder.tvStartHasYearmonth = (TextView) view.findViewById(R.id.tv_start_has_yearmonth);
            viewHolder.tvRelativeHasWorker = (TextView) view.findViewById(R.id.tv_relative_has_worker);
            viewHolder.tvIsNewIn = (TextView) view.findViewById(R.id.tv_is_new_in);

            view.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        PublicityOfApplyResultListItem publicityOfApplyResultItem = mPublicityList.get(i);

        //viewHolder.tvIndexNo .setText(publicityOfApplyResultItem.getIndexNo());

        if (TextUtils.isEmpty(publicityOfApplyResultItem.getHzname()) == false)
        {
            viewHolder.tvHomeOwnerName .setText(publicityOfApplyResultItem.getHzname());
            viewHolder.tvHomeOwnerName.setVisibility(View.VISIBLE);
        }else {
            viewHolder.tvHomeOwnerName.setVisibility(View.GONE);
        }


        if (TextUtils.isEmpty(publicityOfApplyResultItem.getJtrks()) == false)
        {
            viewHolder.tvFamilyPersonNum .setText(publicityOfApplyResultItem.getJtrks());
            viewHolder.tvFamilyPersonNum.setVisibility(View.VISIBLE);
        }else {
            viewHolder.tvFamilyPersonNum.setVisibility(View.GONE);
        }


        if (TextUtils.isEmpty(publicityOfApplyResultItem.getQsxsny()) == false)
        {
            viewHolder.tvStartHasYearmonth .setText(publicityOfApplyResultItem.getQsxsny());
            viewHolder.tvStartHasYearmonth.setVisibility(View.VISIBLE);
        }else {
            viewHolder.tvStartHasYearmonth.setText("2017年04月");
        }


        if (TextUtils.isEmpty(publicityOfApplyResultItem.getJqsfdbgzry()) == false)
        {
            viewHolder.tvRelativeHasWorker .setText(publicityOfApplyResultItem.getJqsfdbgzry());
            viewHolder.tvRelativeHasWorker.setVisibility(View.VISIBLE);
        }else {
            viewHolder.tvRelativeHasWorker.setText("否");
        }


        if (TextUtils.isEmpty(publicityOfApplyResultItem.getSfxj()) == false)
        {
            viewHolder.tvIsNewIn .setText(publicityOfApplyResultItem.getSfxj());
            viewHolder.tvIsNewIn.setVisibility(View.VISIBLE);
        }else {
            viewHolder.tvIsNewIn.setText("否");
        }



        //viewHolder.tvStartHasYearmonth  .setText(publicityOfApplyResultItem.getStartHasYearMonth());
        //viewHolder.tvRelativeHasWorker  .setText(publicityOfApplyResultItem.getIsRelativeAssociate());
        //viewHolder.tvIsNewIn  .setText(publicityOfApplyResultItem.getIsNewIn());

        return view;
    }


    static class ViewHolder {
        private TextView tvIndexNo;
        private TextView tvHomeOwnerName;
        private TextView tvFamilyPersonNum;
        private TextView tvStartHasYearmonth;
        private TextView tvRelativeHasWorker;
        private TextView tvIsNewIn;

    }
}


